<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class LofficeController extends Controller
{
	public function getIndex(Request $request)
    {
        if($request['name']){
            $res = DB::table('person')
            ->join('leaveoffice','leaveoffice.LeaveOfficeID','=','person.id')
            ->where('person.PersonName','like','%'.$request['name'].'%')
            ->select('person.PersonName','leaveoffice.LeaveOfficeID','leaveoffice.LeaveReason','leaveoffice.LeaveTime','leaveoffice.Status')
            ->orderby('leaveoffice.Status','asc')
            ->paginate(4);
        }else{

            $res = DB::table('person')
            ->join('leaveoffice','leaveoffice.PersonID','=','person.id')
            ->select('person.PersonName','leaveoffice.LeaveOfficeID','leaveoffice.LeaveReason','leaveoffice.LeaveTime','leaveoffice.Status')
            ->orderby('leaveoffice.Status','asc')
            ->paginate(4);

            // dd($res);
        }
        $info = $request->all();
        $num1 = count(DB::table('adjust')->where('Status',0)->get());
        $num2 = count(DB::table('leaveoffice')->where('Status',0)->get());
        $num3 = count(DB::table('leave')->where('State',0)->get());
        // dd($num);
        return view('allow/loffice/loffice',['res'=>$res,'info'=>$info,'num1'=>$num1,'num2'=>$num2,'num3'=>$num3]);
    }

    //审批
    public function getEdit($id)
    {
        //修改状态
        DB::table('leaveoffice')->where('LeaveOfficeID',$id)->update(['Status'=>1]);
        return redirect('allow/loffice');
    }
}
